package com.cqc.lite.web;


import com.cqc.lite.domain.Permission;
import com.cqc.lite.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/permission/")
public class PermissionController {

    private final PermissionService permissionService;
    @Autowired
    public PermissionController(PermissionService permissionService){
        this.permissionService=permissionService;
    }


    @GetMapping("findAll.do")
    public ModelAndView findAll(){
        ModelAndView mv = new ModelAndView();
        List<Permission> permissionList = permissionService.findAll();
        mv.addObject("permissionList",permissionList);
        mv.setViewName("permission-list");
        return mv;
    }

    @PostMapping("save.do")
    public String save(Permission permission){
        int save = permissionService.save(permission);
        return "redirect:/permission/findAll.do";
    }
}
